<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class BgcmsMyProfile extends BgcmsProcess{
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty) {
		$this->db = $db;
		$this->smarty = $smarty;
	}
		
	public function __destruct() {
		//
	}
	
    public function edit_my_profile() {
		$arr = array();
		$arr['code'] = 0;
		$arr['message'] = "";
		if(BgcmsUserBean::existed_user_by_id($this->db, $_POST['user_id']) == false) {
			$arr['code'] += 6;
			$arr['message'] .= $this->msg[6];
		} else if($_POST['user_password'] == "") {
			$arr['code'] += 2;
			$arr['message'] .= $this->msg[2];
		} else if($_POST['user_password'] != $_POST['user_password2']) {
			$arr['code'] += 3;
			$arr['message'] .= $this->msg[3];
		} else if($_POST['user_email'] == "") {
			$arr['code'] += 5;
			$arr['message'] .= $this->msg[5];
		}
		
		if($arr['code'] == 0) {
			$arr['message'] = _("User information has been updated.");
			$res = BgcmsUserBean::update_user($this->db, $_POST,'myprofile');
			if($res == false) {
				$arr['code'] += 7;
				$arr['message'] = $this->msg[7];
				
			}
			header("Location: ./?module=BgcmsMyProfile");
		}
		
		if($arr['code'] != 0) {
			$arr['message'] = "<b>". _("User information doesn't updated") . "</b>" . 
								"<br />" . $arr['message'] .$arr['code'];	
		}
		$this->smarty->assign('resp_message', $arr['message']);
	}
	
	public function process() {
		if(isset($_POST['act'])) {
			$act = $_POST['act'];
			if($act == "edituser") {
				$this->edit_my_profile();
			}
		}
		$id = @$_SESSION['user_id'];
		$user = BgcmsUserBean::get_user_by_id($this->db, $id);
		$this->smarty->assign("THEUSER", $user);
		$this->Run();

	}
}
?>